/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dequestackqueue;

/**
 *
 * @author User
 */
public class Deque 
{
    private List begin;
    private List end;
    private List cur;
    Deque()
    {
        begin=null;
        end=null;
        cur=null;
    }
    public void pushbegin(int w)
        {
            cur = new List(w,begin);
            cur.next=begin;
            if(begin!=null) begin.prev=cur;
            cur.prev=null;
            begin=cur;
            if(end==null) end=begin;
        }
    public void pushend(int w)
    {
        cur = new List(w, end);
        if(end!=null) end.next=cur;
        cur.next=null;
        cur.prev=end;
        end=cur;
    }
    public void popbegin()
    {
        if(begin==null) System.err.println("Repository is empty");
        System.out.println(begin.value);
        begin=begin.next;
        if(begin!=null) begin.prev=null;
    }
     public void popend()
    {
        if(end==null) System.err.println("Repository is empty");
        System.out.println(end.value);
        end=end.prev;
        if(end!=null) end.next=null;
    }
}
